package com.lyy.photovoltaic.controller;

import com.lyy.photovoltaic.beans.Equipments;
import com.lyy.photovoltaic.common.vo.ResultCode;
import com.lyy.photovoltaic.common.vo.ResultVO;
import com.lyy.photovoltaic.service.EquipmentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/equipments")
@Api(value = "提供设备的增删改查接口", tags = "设备管理")
@CrossOrigin
public class EquipmentController {
    @Autowired
    private EquipmentsService equipmentsService;

    @PostMapping(value = "/{eid}")
    public ResultVO addEquipment(@PathVariable("eid") String eId,@RequestBody Equipments equipment) {
        //增加设备
//        System.out.println("controller的eId"+eId);
        ResultVO resultVO = equipmentsService.addEquipment(eId,equipment);
//        System.out.println("插入成功了");
        return resultVO;
    }

    @DeleteMapping(value = "/{eid}")
    @ApiImplicitParam(dataType = "string", name = "eid", value = "要删除的设备id", required = true)
    public ResultVO deleteEquipment(@PathVariable("eid") String eId) {
        ResultVO resultVO = equipmentsService.deleteEquipments(eId);
        return resultVO;
    }

    @PutMapping(value = "/{eid}")
    public ResultVO updateEquipment(@RequestBody Equipments equipment) {
        ResultVO resultVO = equipmentsService.updateEquipment(equipment);
        return resultVO;
    }
    @GetMapping(value = "/{eid}")
    @ApiImplicitParam(dataType = "string", name = "eid", value = "要查询的设备id", required = true)
    public ResultVO getEquipment(@PathVariable("eid") String eId) {
//        System.out.println("controller的eId"+eId);

        ResultVO resultVO = equipmentsService.getEquipment(eId);
        return resultVO;
    }
    @PostMapping(value = "/equipmentsLists")
    public ResultVO findEquipmentsList(@RequestBody String[] strings) {
//        System.out.println("controller的eId"+eId);
        ResultVO resultVO = equipmentsService.findEquipmentsList(strings);
        return resultVO;
    }

    @PostMapping(value = "/findall")
    //@ApiImplicitParam(dataType = "string", name = "token", value = "用户授权令牌", required = true)
    public ResultVO findAllEquipment() {
//        System.out.println("找到所有信息了");
        //查看所有设备信息
        ResultVO resultVO = equipmentsService.findAllEquipments();
        return resultVO;
    }
    @PostMapping(value = "/findByPages")
    //@ApiImplicitParam(dataType = "header", name = "token", value = "用户授权令牌", required = true)
    public ResultVO listEquipment() {
        //查看所有设备信息
        ResultVO resultVO = equipmentsService.findEquipmentsByPages();
        return resultVO;
    }
    @GetMapping(value = "/hotEquipmentsList/{pageNum}")
    @ApiImplicitParam(dataType = "int", name = "pageNum", value = "选取分页页数", required = true)
    public ResultVO hotEquipmentsList(@PathVariable("pageNum") int pageNum) {
        //首页查看设备信息
        ResultVO resultVO = equipmentsService.hotEquipmentsList(pageNum);
        return resultVO;
    }
    @GetMapping(value = "/transformerEquipmentsList")
    //@ApiImplicitParam(dataType = "header", name = "token", value = "用户授权令牌", required = true)
    public ResultVO transformerEquipmentsList() {
        //首页查看设备信息
        ResultVO resultVO = equipmentsService.transformerEquipmentsList();
        return resultVO;
    }
    @GetMapping(value = "/indexEquipmentsList")
    //@ApiImplicitParam(dataType = "header", name = "token", value = "用户授权令牌", required = true)
    public ResultVO indexEquipmentsList() {
        //首页查看设备信息
        ResultVO resultVO = equipmentsService.indexEquipmentsList();
        return resultVO;
    }
    @GetMapping(value = "/category/{cid}")
    @ApiImplicitParam(dataType = "string", name = "cid", value = "根据类别查询设备", required = true)
    public ResultVO findEquipmentByCategory(@PathVariable("cid") String categoryId) {
//        System.out.println("controller的eId"+eId);
//        System.out.println("查询成功了");
        ResultVO resultVO = equipmentsService.findEquipmentByCategory(categoryId);
        return resultVO;
    }
    @GetMapping(value = "/index/{input}")
    @ApiImplicitParam(dataType = "string", name = "input", value = "用户输入条件", required = true)
    public ResultVO findEquipmentsByExample(@PathVariable("input") String input) {

        //查看所有设备信息
        ResultVO resultVO = equipmentsService.findEquipmentsByExample(input);
        return resultVO;
    }
    @GetMapping(value = "/name/{name}")
    @ApiImplicitParam(dataType = "string", name = "name", value = "通过点击获取的设备名称", required = true)
    public ResultVO findEquipmentsByName(@PathVariable("name") String name) {
        //通过点击获取的设备名称
        ResultVO resultVO = equipmentsService.findEquipmentsByName(name);
        return resultVO;
    }
    @GetMapping(value = "/imageUrl/{imageUrl}")
    @ApiImplicitParam(dataType = "string", name = "imageUrl", value = "通过点击图片获取的设备名称", required = true)
    public ResultVO findEquipmentsByImageUrl(@PathVariable("imageUrl") String imageUrl) {
        //通过点击获取的设备名称
        ResultVO resultVO = equipmentsService.findEquipmentsByImageUrl(imageUrl);
        return resultVO;
    }
}
